<template>
  <div class="top_bar">
    <div class="title">科普文章</div>
  </div>
  <van-divider></van-divider>
  <div class="nav_and_more">
    <div class="nav">
      <div
        v-for="tab in tabList"
        :key="tab.id"
        class="tab_item"
        @click="flag = tab.id"
      >
        <p :class="[flag == tab.id ? 'active_tab' : 'tab_content']">
          {{ tab.title }}
        </p>
      </div>
    </div>
    <div class="more">
      <div class="shadow"></div>
      <van-icon name="apps-o" :size="size" />
    </div>
  </div>
  <van-list
    :finished="finished"
    finished-text="没有更多了"
    class="article_list"
  >
    <div v-for="article in tabList[flag - 1].essayListData" :key="article.id">
      <div class="cell" @click="jumpDetail(article.id)">
        <div class="title_date_prop">
          <div class="title">
            {{ article.title }}
          </div>
          <div class="date">
            {{ article.date }}
          </div>
          <div class="prop">
            <p class="category">#{{ article.category }}</p>
            <p class="tag">#{{ article.tag }}</p>
          </div>
        </div>
        <img src="" alt="" />
      </div>
      <van-divider></van-divider>
    </div>
  </van-list>
</template>

<script>
import { reactive, ref, watch } from 'vue'
import { useRouter } from 'vue-router'
import { essayCategory } from './mock'
export default {
  setup() {
    let router = useRouter()
    let tabList = reactive(essayCategory)
    let size = ref((document.documentElement.clientWidth / 375) * 14)
    let flag = ref(1)
    let finished = ref(false)
    //少于4条
    watch(
      () => tabList[flag.value - 1].essayListData.length,
      (newValue) => {
        if (newValue < 4) {
          finished.value = true
        } else {
          finished.value = false
        }
      }
    )
    let jumpDetail = (id) => {
      router.push({
        name: 'articleDetail',
        query: {
          id: id,
        },
      })
    }
    return {
      tabList,
      flag,
      router,
      jumpDetail,
      size,
      finished,
    }
  },
} 
</script>

<style lang="less" scoped>
* {
  padding: 0;
  margin: 0;
}
.top_bar {
  width: 100%;
  height: 43px;
  background: #ffffff;
  border-radius: 10px 10px 0px 0px;
  margin-top: 10px;
  .title {
    height: 43px;
    font-size: 15px;
    line-height: 43px;
    font-weight: bold;
    text-align: left;
    color: #333333;
    margin-left: 12px;
  }
}
.nav_and_more {
  display: flex;
  .nav {
    background: #ffffff;
    display: flex;
    height: 30px;
    width: 300px;
    overflow-x: auto;
    .tab_item {
      width: 55px;
      height: 30px;
      .tab_content {
        width: 30px;
        height: 30px;
        line-height: 30px;
        font-size: 14px;
        font-weight: 500;
        color: #999999;
        padding-left: 10px;
        padding-right: 15.5px;
      }
      .active_tab {
        width: 30px;
        height: 30px;
        line-height: 30px;
        font-size: 14px;
        font-weight: 700; 
        color: #333333;
        padding-left: 12.5px;
        padding-right: 15.5px;
        position: relative;
        &:after {
          content: '';
          width: 16px;
          height: 4px;
          background: linear-gradient(#258beb 0%, #25c3eb 100%);
          border-radius: 2px;
          position: absolute;
          left: 40%;
          transform: translateX(-50%);
          bottom: 0;
        }
      }
    }
  }
  ::-webkit-scrollbar {
    display: none;
  }
  .more {
    height: 30px;
    width: 45px;
    background: #ffffff;
    display: flex;
    justify-content: center;
    align-items: center;
    padding-right: 11px;
    .shadow {
      width: 8px;
      height: 23px;
      background: linear-gradient(to right, #ffffff 0%, #f1f1f1 100%);
    }
    .van-icon {
      margin-left: 12px;
    }
  }
}

.article_list {
  background: #ffffff;
  .cell {
    background: #ffffff;
    padding: 21.5px 11px 15.5px 13.5px;
    display: flex;
    .title_date_prop {
      margin-right: 19.5px;
      .title {
        width: 214px;
        font-size: 14px;
        font-weight: 700;
        color: #333333;
      }
      .date {
        margin-top: 11px;
        margin-bottom: 11.5px;
        font-size: 12px;
        font-weight: 500;
        color: #999999;
      }
      .prop {
        display: flex;
        font-size: 12px;
        font-weight: 500;
        color: #258beb;
        transform: scale(0.9);   
        .category{
          margin-left: -11px;
          margin-right: 27px;
        }
      }
    }
    img {
      background: #999999;
      width: 88px;
      height: 75px;
      background: #d2d2d2;
      border-radius: 10px;
      margin-top: -2px;
    }
  }
}
</style>
